<?php
namespace app\index\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\Request;

class Qun extends Base
{
   public function index()
    {
 //获取用户信息开始 
    $dwz= input('dwz');
    $urlData = Db::name('urls')->where('type',2)->where('wx',1)->orderRaw('rand()')->limit(1)->select()->toArray();
    if($urlData){
     Header("Location:http://".$urlData[0]['url']."/index/qun/luodi?dwz=".$dwz);     
    }else{
      echo('没有可用域名了，请联系上级处理');
    }
    
     
    
    }
    public function luodi()
    {
   
    $url=$_SERVER['HTTP_HOST'];
    $urlData = Db::name('urls')->where('url',$url)->where('type',1)->find();//一维数组
    if($urlData){
    Header("Location:http://baidu.com");
    }
 //获取用户信息开始 
    $dwz= input('dwz');
   
    $ip = $_SERVER["REMOTE_ADDR"];
   
    $time=time();
    $data['ip']=$ip;
    $data['time']=$time;
    
  //获取用户信息结束 
   //获取配置信息开始
    $dailiData = Db::name('daili')->where('dwz',$dwz)->find();//一维数组
    if($dailiData['zidingyi']==1){
     $uid=0;   
    }else{
     $uid= $dailiData['id'];   
    }
    
    
    
    $data['uid']=$dailiData['id'];
    $configData = Db::name('danqun')->where('uid',$uid)->find();//一维数组
    
    $name=json_decode($configData['name'],true);
    $img=json_decode($configData['img'],true);
    $overview=json_decode($configData['overview'],true);
    $member=json_decode($configData['member'],true);
    $GroupFriendsShow=json_decode($configData['GroupFriendsShow'],true);
    $GroupBenefits=json_decode($configData['GroupBenefits'],true);
    $ask=json_decode($configData['ask'],true);
    $interlocution=json_decode($configData['interlocution'],true);
    $yuedudianzanshu=json_decode($configData['yuedudianzanshu'],true);
    $lianxikefu=json_decode($configData['lianxikefu'],true);
   //获取用户信息结束
    // $shouquanurldata=$this->qingqiu();
    $touxiangData = Db::name('danqunlist')->where('uid',$uid)->where('type',1)->paginate([
              'list_rows'=> $member['xianshishuliang'],//每页数量
              'query' => request()->param(),
              ]);
     $fuliData = Db::name('danqunlist')->where('uid',$uid)->where('type',3)->paginate([
              'list_rows'=> 20,//每页数量
              'query' => request()->param(),
              ]);      
       $askdata = Db::name('danqunlist')->where('uid',$uid)->where('type',4)->paginate([
              'list_rows'=> 20,//每页数量
              'query' => request()->param(),
              ]);    
         $liuyandata = Db::name('danqunlist')->where('uid',$uid)->where('type',5)->paginate([
              'list_rows'=> $interlocution['xianshitiaoshu'],//每页数量
              'query' => request()->param(),
              ]);   
    
   $userData = Db::name('users')->where('ip',$data['ip'])->where('uid',$dailiData['id'])->find();//一维数组
 
                
 
 if($userData==NULL){
   $res=Db::name('users')->insertGetId($data);
   $user = Db::name('users')->where('id',$res)->find();//一维数组
   $id=$user['id'];
 }else {
     $res= Db::name('users')->where('id', $userData['id'])->update(['logotime' => $time]);
      $user = Db::name('users')->where('id',$userData['id'])->find();//一维数组
      $id=$user['id'];
 }
 $payconfig= Db::name('pay')->where('state',1)->orderRaw('rand()')->limit(1)->select()->toArray();
   
      $pay= Db::name('users')->where('ip',$ip)->where('uid',$dailiData['id'])->find();
    
      $ispay= Db::name('order')->where('uid',$pay['id'])->where('status',2)->where('dailiuid',$dailiData['id'])->find();
     

 
      if($ispay==NULL){
       $ispay='1';
      }else{
        $ispay='2';   
      }

   if($dailiData['zidingyi']==1){
     $uid= $dailiData['id'];
    }
   
 //获取用户信息结束
        return view('',[
           'lianxikefu'=>$lianxikefu, 
         'img'=>$img,
         'payconfig'=>$payconfig[0],
         'name'=>$name,
         'member'=>$member,
         'touxiangData'=>$touxiangData,
         'overview'=>$overview,
         'show'=>$GroupFriendsShow,
          'fuli'=>$GroupBenefits,
          'fuliData'=>$fuliData,
          'ask'=>$ask,
          'askdata'=>$askdata,
          'yuedu'=>$yuedudianzanshu,
          'liuyan'=>$interlocution,
           'liuyandata'=>$liuyandata,
            'uid'=>$uid,
            'id'=>$id,
            'ispay'=>$ispay,
            'dwz'=>$dwz,
       
        ]);
    }
public function qunyouxiulist(){
     $dwz= input('dwz');
      $dailiData = Db::name('daili')->where('dwz',$dwz)->find();//一维数组
   $uid= $dailiData['id'];
         $GroupFriendsShow = Db::name('danqunlist')->where('uid',$uid)->where('type',2)->paginate([
              'list_rows'=> 50,//每页数量
              'query' => request()->param(),
              ]);  
       
     return view('',[
       
        'show'=>$GroupFriendsShow,
        ]);
}
 public function liuyanlist(){
       $dwz= input('dwz');
      $dailiData = Db::name('daili')->where('dwz',$dwz)->find();//一维数组
   $uid= $dailiData['id'];
         $liuyandata = Db::name('danqunlist')->where('uid',$uid)->where('type',5)->paginate([
              'list_rows'=> 50,//每页数量
              'query' => request()->param(),
              ]);  
     return view('',[
          'liuyandata'=>$liuyandata,
       
        ]);
}
  public function paid(){
     $dwz= input('dwz');
     $dailiData = Db::name('daili')->where('dwz',$dwz)->find();//一维数组
     if($dailiData['zidingyi']==1){
      $uid= 0;   
     }else{
      $uid= $dailiData['id'];
     }
     
  
      $ip = $_SERVER["REMOTE_ADDR"];
      if($dailiData['zidingyi']==1){
     $pay= Db::name('users')->where('ip',$ip)->where('uid',$dailiData['id'])->find();
     }else{
     $pay= Db::name('users')->where('ip',$ip)->where('uid',$uid)->find();
     }
      
     
      $pays= Db::name('order')->where('uid',$pay['id'])->where('status',2)->where('dailiuid',$pay['uid'])->find();
      if($pays==NULL){
         header('location:/index/qun?dwz='.$dwz);  
         exit;
      }
      
  
         $paid = Db::name('paid')->where('uid',$uid)->find();
  
     return view('',[
          'paid'=>$paid,
       
        ]);
}
 
   

  
}
